<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class FrontAuth{
    var $_auth_session = 'user_auth_logged';
    function FrontAuth(){
        
    }
    
    function is_logged(){
        $CI = &get_instance();
        return $CI->session->userdata($this->_auth_session);
    }
    
    function get_auth_data(){
        $CI = &get_instance();
        return $CI->session->userdata($this->_auth_session);
    }
    
    function logged($user_data){
        $CI = &get_instance();
        $CI->session->set_userdata($this->_auth_session, $user_data);
        $this->forward();
    }
    
    function forward($url = ''){
        $CI = &get_instance();
        if(!empty($url))
            redirect($url);

        if($CI->session->userdata('redirect_page')){
            $url = $CI->session->userdata('redirect_page');
            $CI->session->unset_userdata('redirect_page');
            redirect($url);
        }
        
        redirect('Trang-Chu');
    }
    
    function logout(){
        $CI = &get_instance();
        $CI->session->destroy(); // sess_destroy();
        redirect('Trang-Chu');
    }
}
?>